local global = require "global"
local Map = require "map.map"
local MapInstance = require "map.map_instance"
local t_scene_config = require "config.scene"

MapMgr = {}

function MapMgr:New(o)
    o = o or {}	
	self.__index = self
	setmetatable(o, self)
	
	o.world_scene_map_ = {}
	o.instance_scene_map_ = {}
	o.map_serial_idx_ = 0

    return o
end

function MapMgr:get_world_sence( scene_type_idx )
	return self.world_scene_map_[scene_type_idx]
end

function MapMgr:get_instance_sence( scene_obj_idx )
	return self.instance_scene_map_[scene_obj_idx]
end

function MapMgr:CreateMap()
	for index, value in pairs(t_scene_config) do
		if value.area_idx == global.config.area_idx then
			local map = Map:New()
			map:set_config(t_scene_config[index])
			self.world_scene_map_[map:get_id()] = map
		end
	end
end

function MapMgr:CreateMapInstance( scene_type_idx, create_param )
	-- const db::config::ConfigScene *scene_info = SceneConfigManager::get_instance()->GetSceneInfo(scene_type_idx)

	-- local obj_idx = self:MakeGeneralID()

	-- local instance = MapInstance:New()
	-- --instance:set(obj_idx, scene_info, create_param)
	-- instance_scene_map_.insert(make_pair(instance:get_obj_idx(), instance))
	-- return instance
end

function MapMgr:DestoryMapInstance( obj_idx )
	local map_instance = self.instance_scene_map_[obj_idx]
	if map_instance then
		self.instance_scene_map_[obj_idx] = nil
	end
end

function MapMgr:MakeGeneralID()
	self.map_serial_idx_ = self.map_serial_idx_ + 1
	return MAKE_PAIR64_10(global.server_res_mgr:get_serial_idx(), self.map_serial_idx_)
end

function MapMgr:get_instance_count()
	return table_len(self.instance_scene_map_)
end

return MapMgr